<template>
  <div class="sub-tabs">
    <el-tabs v-model="activeTab">
      <el-tab-pane label="最近学习" name="recent">
        <div class="learning-records">
          <el-card v-for="(record, index) in learningRecords" :key="index" class="record-card">
            <div class="record-content">
              <div class="record-image" v-if="record.image">
                <img :src="record.image" :alt="record.title">
              </div>
              <div class="record-info">
                <h3 class="record-title" @click="viewLearningRecord(record)">{{ record.title }}</h3>
                <div class="record-progress">
                  <el-progress 
                    :percentage="record.progress" 
                    :status="record.progress === 100 ? 'success' : ''"
                  ></el-progress>
                </div>
                <div class="record-meta">
                  <span>{{ record.subject }}</span>
                  <span>{{ record.lastStudyTime }}</span>
                  <span>学习{{ record.studyDuration }}分钟</span>
                </div>
              </div>
            </div>
            <div class="record-actions">
              <el-button type="primary" size="small" @click="continueLearning(record)">继续学习</el-button>
              <el-button type="info" size="small" @click="viewLearningRecord(record)">查看详情</el-button>
            </div>
          </el-card>
        </div>
        
        <div class="empty-data" v-if="learningRecords.length === 0">
          <el-empty description="暂无学习记录"></el-empty>
        </div>
      </el-tab-pane>
      
      <el-tab-pane label="收藏课程" name="favorites">
        <div class="favorite-courses">
          <el-card v-for="(course, index) in favoriteCourses" :key="index" class="course-card">
            <div class="course-content">
              <div class="course-image">
                <img :src="course.image" :alt="course.title">
              </div>
              <div class="course-info">
                <h3 class="course-title" @click="viewCourse(course)">{{ course.title }}</h3>
                <div class="course-meta">
                  <span>{{ course.subject }}</span>
                  <span>{{ course.teacher }}</span>
                  <span>{{ course.studentsCount }}人学习</span>
                </div>
                <div class="course-price" v-if="course.price">
                  <span class="current-price">¥{{ course.price }}</span>
                  <span class="original-price" v-if="course.originalPrice">¥{{ course.originalPrice }}</span>
                </div>
              </div>
            </div>
            <div class="course-actions">
              <el-button type="primary" size="small" @click="viewCourse(course)">查看课程</el-button>
              <el-button type="danger" size="small" @click="removeFavorite(course)">取消收藏</el-button>
            </div>
          </el-card>
        </div>
        
        <div class="empty-data" v-if="favoriteCourses.length === 0">
          <el-empty description="暂无收藏课程"></el-empty>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';

const router = useRouter();
const activeTab = ref('recent');

const props = defineProps({
  learningRecords: {
    type: Array,
    default: () => []
  },
  favoriteCourses: {
    type: Array,
    default: () => []
  }
});

const emit = defineEmits(['remove-favorite']);

// 方法：继续学习
const continueLearning = (record) => {
  router.push(`/course/${record.id}`);
};

// 方法：查看学习记录
const viewLearningRecord = (record) => {
  router.push(`/course/${record.id}/detail`);
};

// 方法：查看课程
const viewCourse = (course) => {
  router.push(`/course/${course.id}`);
};

// 方法：取消收藏课程
const removeFavorite = (course) => {
  emit('remove-favorite', course);
};
</script>

<style scoped>
.sub-tabs {
  margin-top: 20px;
}

/* 学习记录卡片样式 */
.record-card, .course-card {
  margin-bottom: 20px;
  transition: all 0.3s;
}

.record-card:hover, .course-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.record-content, .course-content {
  display: flex;
  margin-bottom: 15px;
}

.record-image, .course-image {
  width: 120px;
  height: 80px;
  overflow: hidden;
  border-radius: 4px;
  margin-right: 15px;
  flex-shrink: 0;
}

.record-image img, .course-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.record-info, .course-info {
  flex: 1;
}

.record-title, .course-title {
  margin: 0 0 10px 0;
  font-size: 16px;
  cursor: pointer;
  color: #303133;
}

.record-title:hover, .course-title:hover {
  color: #409EFF;
}

.record-progress {
  margin-bottom: 10px;
}

.record-meta, .course-meta {
  display: flex;
  color: #909399;
  font-size: 13px;
}

.record-meta span, .course-meta span {
  margin-right: 15px;
}

.record-actions, .course-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* 收藏课程价格样式 */
.course-price {
  margin-top: 10px;
}

.current-price {
  color: #f56c6c;
  font-weight: bold;
  font-size: 16px;
  margin-right: 10px;
}

.original-price {
  color: #909399;
  text-decoration: line-through;
  font-size: 14px;
}

/* 空数据样式 */
.empty-data {
  padding: 30px 0;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .record-content, .course-content {
    flex-direction: column;
  }
  
  .record-image, .course-image {
    width: 100%;
    height: 150px;
    margin-right: 0;
    margin-bottom: 15px;
  }
}
</style>